package org.boticelli.util;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

import java.util.Calendar;

import org.junit.Test;

public class DateUtilTestCase
{
    @Test
    public void thatFromDaySinceEpochWorks()
    {
        Calendar cal = DateUtil.fromDaySinceEpoch(0);
        assertThat(cal.get(Calendar.YEAR), is(1970));
        assertThat(cal.get(Calendar.MONTH), is(0));
        assertThat(cal.get(Calendar.DAY_OF_MONTH), is(1));

        cal = DateUtil.fromDaySinceEpoch(31);
        assertThat(cal.get(Calendar.YEAR), is(1970));
        assertThat(cal.get(Calendar.MONTH), is(1));
        assertThat(cal.get(Calendar.DAY_OF_MONTH), is(1));

        cal = DateUtil.fromDaySinceEpoch(365);
        assertThat(cal.get(Calendar.YEAR), is(1971));
        assertThat(cal.get(Calendar.MONTH), is(0));
        assertThat(cal.get(Calendar.DAY_OF_MONTH), is(1));
        
        cal=Calendar.getInstance();
        DateUtil.zeroTimeFields(cal);
        assertThat( DateUtil.fromDaySinceEpoch(DateUtil.daySinceEpoch(cal)), is (cal) );              
    }
}
